﻿using FHJFPro.Enum;
using FHJFPro.UserInfos.Repositories;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Services;

namespace FHJFPro.UserInfos
{
    public class UserInfoManager : DomainService
    {
        private readonly IUserInfoRepository _userInfoRepository;
        public UserInfoManager(IUserInfoRepository userInfoRepository)
        {
            _userInfoRepository = userInfoRepository;
        }
        public async Task<UserInfo> CreateAsync(
           [NotNull] string userName,
           [NotNull] string passWord,
           [NotNull] GenderEnum gender,
           [CanBeNull] string description)
        {
            Check.NotNullOrWhiteSpace(userName, nameof(userName));

            var existingAuthor = await _userInfoRepository.FindByNameAsync(userName);
            if (existingAuthor != null)
            {
                throw new UserInfoAlreadyExistsException(userName);
            }

            return new UserInfo( GuidGenerator.Create(),userName,passWord,gender,description );
        }

    }
}
